from django.contrib.auth.backends import ModelBackend
from django.shortcuts import render
from django.views.decorators import http
from rest_framework import mixins
from rest_framework import request
from rest_framework import status
from rest_framework.generics import GenericAPIView, CreateAPIView
from rest_framework.views import APIView,Response

from .serializers import Register
from .models import User

#用户名移除事件判断用户是否存在
class CheckUsername(APIView):
    def get(self,request,username):
        #1.校验数据
        count = User.objects.filter(username=username).count()

        #2.整理数据
        data = {
            "count":count
        }

        #3.返回响应
        return Response(data,status=status.HTTP_200_OK)
#用户名移除事件判断手机号是否存在
class CheckMobile(APIView):
    def get(self,request,mobile):
        count = User.objects.filter(mobile=mobile).count()

        data = {
            "count":count
        }


        return Response(data,status=status.HTTP_200_OK)
#注册(三级视图)
class RegisterView(CreateAPIView):
    serializer_class = Register

